﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Security.Permissions;

namespace Sample.Reflection
{
    public class ReflectionFunction
    {
        public ReflectionFunction()
        {

        }

        public int Test()
        {
            return 0;
        }

        public static void Execute()
        {
            Assembly assem = Assembly.GetExecutingAssembly();

            Console.WriteLine("Assembly Full Name:");
            Console.WriteLine(assem.FullName);

            // The AssemblyName type can be used to parse the full name.
            AssemblyName assemName = assem.GetName();
            Console.WriteLine("\nName: {0}", assemName.Name);
            Console.WriteLine("Version: {0}.{1}",
                assemName.Version.Major, assemName.Version.Minor);

            Console.WriteLine("\nAssembly CodeBase:");
            Console.WriteLine(assem.CodeBase);

            Console.WriteLine("\nThere are these types in the assembly:");
            foreach (Type aType in assem.GetTypes())
            {
                Console.WriteLine(aType.Name);
            }
            Console.WriteLine();

            // Create an object from the assembly, passing in the correct number
            // and type of arguments for the constructor.
            Object o = assem.CreateInstance("Test_ConsoleApplication.ReflectionFunction", false,
                BindingFlags.ExactBinding,
                null, new Object[] {  }, null, null);

            // Make a late-bound call to an instance method of the object.    
            MethodInfo m = Assembly.Load(assemName).GetType("Test_ConsoleApplication.ReflectionFunction").GetMethod("Test");
            Object ret = m.Invoke(o, new Object[] {  });
            Console.WriteLine("SampleMethod returned {0}.", ret);

            Console.WriteLine("\nAssembly entry point:");
            Console.WriteLine(assem.EntryPoint);

        }     
    }
}
